package com.example.controller;
import cn.hutool.core.util.StrUtil;
import com.example.pojo.Result;
import com.example.pojo.userPojo;
import com.example.service.userService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * ClassName:userController
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/5/8 18:04
 * @Version 1.0
 */
@RestController
@Slf4j
public class userController {
    @Autowired
    private userService userService;
    @PostMapping("/UserLogin")
    public Result UserLogin(@RequestBody userPojo user){
        if(StrUtil.isBlank(user.getUserName()) || StrUtil.isBlank(user.getPassword())){
            return Result.error(500,"数据输入不合法");
        }
        userPojo dbJWT= userService.userLogin(user);
        return Result.success(dbJWT);
    }

    //质量问题管理页请求验证用户权限
    @PostMapping("/problemUse")
    public Result problemUse(@RequestBody String user){
        int useType =userService.fieldByOne("problemManagement",user);
        return Result.success(useType);
    }
    //根据前端发来的请求字段，查询在固定的用户下，固定的权限内容。
    @PostMapping("/problemUsePurview")
    public Result problemUsePurview(@RequestBody Map<String, Object> parameters){
        userPojo userPojo=userService.problemUsePurview(parameters);
        return Result.success(userPojo);
    }
    //前端发来请求，按照用户的工号，查询用户名称和用户对应的页面权限
    @PostMapping("/useQueryPower")
    public Result useQueryPower(@RequestBody Map<String, Object> parameters){
        userPojo userPojo=userService.useQueryPower(parameters);
        return Result.success(userPojo);
    }
    //查询所有的用户信息
    @PostMapping("/queryAllUser")
    public Result queryAllUser(){
        List<userPojo> userPojoList=userService.queryAllUser();
        return Result.success(userPojoList);
    }
    //修改一行数据
    @PostMapping("/editBaseUser")
    public Result editBaseUser(@RequestBody userPojo userPojo){
        userService.editOne(userPojo);
        return Result.success();
    }
    //插入一整行
    @PostMapping("/insertBaseUser")
    public Result insertBaseUser(@RequestBody userPojo userPojo){
        userService.insertOne(userPojo);
        return Result.success();
    }

    //根据id，修改某一个字段的值
    @PostMapping("/userEditOneField")
    public Result userEditOneField(@RequestBody Map<String,Object> map){
        userService.editOneField(map);
        return Result.success("成功");
    }
}
